package snapex.expense.mapper;

import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
import static snapex.expense.mapper.ExpenseMailDynamicSqlSupport.*;

import java.util.List;

import javax.annotation.Generated;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.delete.DeleteDSL;
import org.mybatis.dynamic.sql.delete.MyBatis3DeleteModelAdapter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.render.RenderingStrategy;
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
import org.mybatis.dynamic.sql.select.SelectDSL;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;

import snapex.core.model.ExpenseMail;


@Mapper
public interface HtcExpenseMailMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<ExpenseMail> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("ExpenseMailResult")
    ExpenseMail selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="ExpenseMailResult", value = {        
        @Result(column="expense_id", property="expenseId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER)        
    })
    List<ExpenseMail> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>> countByExample() {
        return SelectDSL.selectWithMapper(this::count, SqlBuilder.count())
                .from(ExpenseMail);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default DeleteDSL<MyBatis3DeleteModelAdapter<Integer>> deleteByExample() {
        return DeleteDSL.deleteFromWithMapper(this::delete, ExpenseMail);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(String ExpenseMailId_) {
        return DeleteDSL.deleteFromWithMapper(this::delete, ExpenseMail)
                .where(expenseId, isEqualTo(ExpenseMailId_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(ExpenseMail record) {
        return insert(SqlBuilder.insert(record)
                .into(ExpenseMail)
                .map(expenseId).toProperty("expenseId")
                .map(status).toProperty("status")
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(ExpenseMail record) {
        return insert(SqlBuilder.insert(record)
                .into(ExpenseMail)
                .map(expenseId).toPropertyWhenPresent("expenseId", record::getExpenseId)
                .map(status).toPropertyWhenPresent("status", record::getStatus)
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<ExpenseMail>>> selectByExample() {
        return SelectDSL.selectWithMapper(this::selectMany, expenseId, status)
                .from(ExpenseMail);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<ExpenseMail>>> selectDistinctByExample() {
        return SelectDSL.selectDistinctWithMapper(this::selectMany, expenseId, status)
                .from(ExpenseMail);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default ExpenseMail selectByPrimaryKey(String ExpenseMailId_) {
        return SelectDSL.selectWithMapper(this::selectOne, expenseId, status)
                .from(ExpenseMail)
                .where(expenseId, isEqualTo(ExpenseMailId_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExample(ExpenseMail record) {
        return UpdateDSL.updateWithMapper(this::update, ExpenseMail)                
                .set(expenseId).equalTo(record::getExpenseId)
                .set(status).equalTo(record::getStatus);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExampleSelective(ExpenseMail record) {
        return UpdateDSL.updateWithMapper(this::update, ExpenseMail)
                .set(expenseId).equalToWhenPresent(record::getExpenseId)
                .set(status).equalToWhenPresent(record::getStatus);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(ExpenseMail record) {
        return UpdateDSL.updateWithMapper(this::update, ExpenseMail)
                .set(expenseId).equalTo(record::getExpenseId)
                .set(status).equalTo(record::getStatus)
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(ExpenseMail record) {
        return UpdateDSL.updateWithMapper(this::update, ExpenseMail)
                .set(expenseId).equalToWhenPresent(record::getExpenseId)
                .set(status).equalToWhenPresent(record::getStatus)
                .build()
                .execute();
    }
}